package com.hopes.bizz.poll.om.service.impl;

import cn.hutool.core.lang.Pair;
import com.hopes.bizz.poll.common.constant.enums.OmHisDataTypeEnums;
import com.hopes.bizz.poll.om.entity.BaseOmDataEntity;
import com.hopes.bizz.poll.om.helper.PollDataTimeParse;
import com.hopes.bizz.poll.om.mapper.PollDataHisMapper;
import com.hopes.bizz.poll.om.service.PollHisDataService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author lyb
 * @version 1.0
 * @date 2023/10/10 15:07
 */

@Service
public class PollHisDataServiceImpl implements PollHisDataService {


    @Resource
    private PollDataHisMapper pollDataHisMapper;

    @Override
    public BaseOmDataEntity getByMonitorSiteIdAndDataTime(Long monitorSiteId, Date dataTime, Integer dataType) {
        String table = OmHisDataTypeEnums.getTableByCode(dataType);
        Pair<Date, Date> parse = PollDataTimeParse.Parse(dataTime, dataType);
        return pollDataHisMapper.selectOneByMonitorSiteIdAndRangeDataTime(monitorSiteId, parse.getKey(), parse.getValue(), table);
    }
}
